package com.chixing.ih.json;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 刘岩
 * @version 1.0
 * @Desc Practice makes perfect
 * @date 2020/9/10 15:21
 */
public class ResponseData {

    /**开发者须知：
     *
     * 1、REP_GET_SUCCESS("200", "服务器成功返回用户请求的数据"),
     * 2、REP_CREATED_SUCCESS("201", "请求成功并且服务器创建新资源"),
     * 3、REP_ACCEPTED_SUCCESS("202", "服务器已接受请求，但尚未处理"),
     * 4、REP_ACCEPTED_NO_HANDLE("204","服务器成功处理了请求，但没有返回任何内容")
     * 5、REP_DELETE_SUCCESS("207", "删除数据成功"),
     * 6、REP_INVALID_ERROR("400", "用户发出的请求有错误，服务器没有进行新建或修改数据的操作"),
     * 7、REP_NO_ACCESS_ERROR("401", "用户没有权限,请求要求身份验证"),
     * 8、REP_NOT_FOUND_ERROR("404", "服务器没有进行操作,访问资源不存在"),
     * 9、REP_GONE_ERROR("405", "用户请求的方式错误"),
     * 10、REP_INTERNAL_SERVER_ERROR("500", "服务器发生错误");
     * 11、REP_INTERNAL_SERVER_EXIST("309", "资源已存在");
     */
    /**
     * @param code
     * @param msg
     * @param content
     * @return 服务器成功返回用户请求的数据
     */

    public static Map<String, Object> result(String code, String msg, Object content) {
        Map<String, Object> responseMap = new HashMap<String, Object>();
        responseMap.put("code", code);
        responseMap.put("message", msg);
        responseMap.put("content", content);
        return responseMap;
    }

    /**
     * @param code
     * @param msg
     * @return 服务器成功返回用户请求content为空
     */

    public static Map<String, Object> result(String code, String msg) {
        Map<String, Object> responseMap = new HashMap<String, Object>();
        responseMap.put("code", code);
        responseMap.put("message", msg);
        responseMap.put("content", "");
        return responseMap;
    }


    /**
     * @param content
     * @return REP_GET_SUCCESS(" 200 ", " 服务器成功返回用户请求的数据 ")
     */

    public static Map<String, Object> REP_GET_SUCCESS(Object content) {
        return result(ResponseState.REP_GET_SUCCESS.code, ResponseState.REP_GET_SUCCESS.message, content);
    }


    /**
     * @return REP_ACCEPTED_NO_HANDLE(" 204 ", " 服务器成功处理了请求 ， 但没有返回任何内容 ")
     */

    public static Map<String, Object> REP_ACCEPTED_NO_HANDLE() {
        return result(ResponseState.REP_GET_SUCCESS.code, ResponseState.REP_GET_SUCCESS.message, "");
    }

    /**
     * @return REP_CREATED_SUCCESS(" 201 ", " 请求成功并且服务器创建新资源 ")
     */

    public static Map<String, Object> REP_CREATED_SUCCESS() {
        return result(ResponseState.REP_CREATED_SUCCESS.code, ResponseState.REP_CREATED_SUCCESS.message, "");
    }

    /**
     * @return REP_ACCEPTED_SUCCESS(" 202 ", " 服务器已接受请求 ， 但尚未处理 ")
     */

    public static Map<String, Object> REP_ACCEPTED_SUCCESS() {
        return result(ResponseState.REP_ACCEPTED_SUCCESS.code, ResponseState.REP_ACCEPTED_SUCCESS.message, "");
    }

    /**
     * @return REP_DELETE_SUCCESS(" 207 ", " 删除数据成功 ")
     */

    public static Map<String, Object> REP_DELETE_SUCCESS() {
        return result(ResponseState.REP_DELETE_SUCCESS.code, ResponseState.REP_DELETE_SUCCESS.message, "");
    }

    /**
     * @return REP_INVALID_ERROR(" 400 ", " 用户发出的请求有错误 ， 服务器没有进行新建或修改数据的操作 ")
     */
    public static Map<String, Object> REP_INVALID_ERROR() {
        return result(ResponseState.REP_INVALID_ERROR.code, ResponseState.REP_INVALID_ERROR.message, "");
    }


    /**
     * @return REP_NO_ACCESS_ERROR(" 401 ", " 用户没有权限, 请求要求身份验证 ")
     */

    public static Map<String, Object> REP_NO_ACCESS_ERROR() {
        return result(ResponseState.REP_NO_ACCESS_ERROR.code, ResponseState.REP_NO_ACCESS_ERROR.message, "");
    }

    /**
     * @return REP_NOT_FOUND_ERROR(" 404 ", " 服务器没有进行操作, 访问资源不存在 ")
     */
    public static Map<String, Object> REP_NOT_FOUND_ERROR() {
        return result(ResponseState.REP_NOT_FOUND_ERROR.code, ResponseState.REP_NOT_FOUND_ERROR.message, "");
    }

    /**
     * @return REP_GONE_ERROR(" 405 ", " 用户请求的方式错误 ")
     */
    public static Map<String, Object> REP_GONE_ERROR() {
        return result(ResponseState.REP_GONE_ERROR.code, ResponseState.REP_GONE_ERROR.message, "");
    }

    /**
     * @return REP_INTERNAL_SERVER_ERROR(" 500 ", " 服务器发生错误 ")
     */

    public static Map<String, Object> REP_INTERNAL_SERVER_ERROR() {
        return result(ResponseState.REP_INTERNAL_SERVER_ERROR.code, ResponseState.REP_INTERNAL_SERVER_ERROR.message, "");
    }

    /**
     *
     * @return REP_INTERNAL_SERVER_EXIST("309", "资源已存在");
     */

    public static Map<String, Object>  REP_INTERNAL_SERVER_EXIST() {
        return result(ResponseState.REP_INTERNAL_SERVER_EXIST.code,  ResponseState.REP_INTERNAL_SERVER_EXIST.message);
    }

}
